const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n,e;
let initArr = [];
rl.on("line", (line) => {
    if (n === undefined) {
        [n, e] = line.trim().split(/\s+/).map(Number)
    } else {
        initArr.push(line.trim().split(/\s+/).map(Number))
        if(initArr.length === e) {
            getResult(n, e, initArr)

            //clear
            n = e = undefined
            initArr.length = 0
            rl.close()
        }
    }
})

function getResult(n, e, initArr) {
    let started = new Array(n).fill(false)
    initArr.sort((a, b) => a[0] - b[0])
    let index = 0
    let pq = []
    let count = n
    let ans
    while(count > 0) {
        ans = [...pq]
        let length = pq.length
        for (let i = 0; i < length ; i++) {
            let num = pq.shift()
            if(!started[num]) {
                started[num] = true
                count--
                spread(num, n, pq, started)
            }
        }

        while(initArr.length && initArr[0][0] === index) {
            // 启动
            if(started[initArr[0][1]] === false) {
                started[initArr[0][1]] = true
                count--
                spread(initArr[0][1], n, pq, started) // 延伸
            }
            initArr.shift()
        }
        index++
    }
    console.log(ans.length)
    console.log(ans.sort((a, b) => a - b).join(" "))
}

function spread(index, n, pq, started) {
    let left = index - 1
    let right = index + 1
    if(left < 0) left = n - 1
    if(right > n - 1) right = 0
    if(!started[left] && pq.indexOf(left) === -1) {
        pq.push(left)
    }
    if(!started[right] && pq.indexOf(right) === -1) {
        pq.push(right)
    }
}
